﻿Imports System.Data.OleDb
Public Class addFilm
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btn_add_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_add.Click
        Dim myGUID = Guid.NewGuid()
        Dim NewfileName As String = myGUID.ToString() & ".jpg"
        Dim fileLocationOnServerHardDisk = Request.MapPath("FilmCovers") & "/" & NewfileName
        fu_cover.SaveAs(fileLocationOnServerHardDisk)
        Dim conn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("godzillaFilms").ConnectionString)
        Dim sql As String = "INSERT INTO releases(FilmID, Format, Region, JapaneseAudio, EnglishSubtitles, Distributor, FrontCover, Uploader) Values (@f1,@f2,@f3,@f4,@f5,@f6,@f7,@f8)"
        Dim cmd As OleDbCommand = New OleDbCommand(sql, conn)
        conn.Open()
        cmd.Parameters.AddWithValue("@f1", ddl_name.SelectedIndex + 1)
        cmd.Parameters.AddWithValue("@f2", ddl_format.SelectedItem.Text)
        cmd.Parameters.AddWithValue("@f3", ddl_region.SelectedItem.Text)
        cmd.Parameters.AddWithValue("@f4", ddl_audio.SelectedItem.Text)
        cmd.Parameters.AddWithValue("@f5", ddl_subs.SelectedItem.Text)
        cmd.Parameters.AddWithValue("@f6", tb_dist.Text)
        cmd.Parameters.AddWithValue("@f7", "FilmCovers/" & NewfileName)
        cmd.Parameters.AddWithValue("@f8", User.Identity.Name)
        cmd.ExecuteNonQuery()
        conn.Close()
        Response.Redirect("releaseList.aspx")
    End Sub
End Class